package com.dbsop.domain.transport.query;

import com.dbsop.common.enums.DecideFlag;
import com.dbsop.common.enums.FlagConnect;
import com.dbsop.domain.transport.res.TransportUtils;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;

public abstract class RangeQuery extends ConditionQuery {

    private Object value;

    private DecideFlag decideFlag;

    private RangeQuery rangeQuery;

    public RangeQuery(String columnName, Object value) {
        super(columnName);
        this.value = value;
    }

    public RangeQuery(String columnName, Object value, DecideFlag decideFlag) {
        super(columnName);
        this.value = value;
        this.decideFlag = decideFlag;
    }

    public RangeQuery(String columnName, FlagConnect flagConnect, Object value) {
        super(columnName, flagConnect);
        this.value = value;
    }


    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    protected void setRangeQuery(RangeQuery rangeQuery) {
        this.rangeQuery = rangeQuery;
    }

    public DecideFlag getDecideFlag() {
        return decideFlag;
    }

    public void setDecideFlag(DecideFlag decideFlag) {
        this.decideFlag = decideFlag;
    }

    @Override
    public QueryBuilder extractBoolQuery() {
        RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(getColumnName());
        TransportUtils.decideFlagHandler(getDecideFlag(),rangeQueryBuilder,getValue());
        if (this.rangeQuery!=null) TransportUtils.decideFlagHandler(rangeQuery.getDecideFlag(),rangeQueryBuilder,rangeQuery.getValue());
        return rangeQueryBuilder;
    }
}
